package main

import (
	"encoding/json"
	"fmt"
	"github.com/nacos-group/nacos-sdk-go/clients"
	"github.com/nacos-group/nacos-sdk-go/common/constant"
	"github.com/nacos-group/nacos-sdk-go/vo"

	"oldpackagetest/config"
)

func main() {
	sc := []constant.ServerConfig{
		*constant.NewServerConfig("192.168.10.130", 8848, constant.WithContextPath("/nacos")),
	}
	cc := *constant.NewClientConfig(
		constant.WithNamespaceId("d35c6a37-2a22-465d-944c-ef3a58c9bee0"),
		constant.WithTimeoutMs(5000),
		constant.WithNotLoadCacheAtStart(true),
		constant.WithLogDir("tmp/nacos/log"),
		constant.WithCacheDir("tmp/nacos/cache"),
		constant.WithLogLevel("debug"),
	)
	client, err := clients.NewConfigClient(
		vo.NacosClientParam{
			ClientConfig:  &cc,
			ServerConfigs: sc,
		},
	)
	if err != nil {
		fmt.Printf("PublishConfig err:%+v \n", err)
	}
	content, err := client.GetConfig(vo.ConfigParam{
		DataId: "user-web.json",
		Group:  "dev",
	})
	//fmt.Println(content)
	serverConfig := config.ServerConfig{}
	//想要将一个字符串转换成struct需要去设置这个struct的tag
	_ = json.Unmarshal([]byte(content), &serverConfig)
	fmt.Println(serverConfig)
}
